
package org.apache.solr.response.transform;

import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;

/**
 * @since solr 4.0
 */
public class DocIdAugmenterFactory extends TransformerFactory {

    @Override
    public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {
        return new DocIdAugmenter(field);
    }
}

class DocIdAugmenter extends DocTransformer {

    final String name;

    public DocIdAugmenter(String display) {
        this.name = display;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void transform(SolrDocument doc, int docid) {
        if(docid >= 0) {
            doc.setField(name, docid);
        }
    }
}
